<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:yui="http://yuilibrary.com/rdf/1.0/yui.rdf#">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<title>API: CWN2   _event.js  (YUI Library)</title>

	<link rel="stylesheet" type="text/css" href="assets/reset-fonts-grids-min.css?stamp=1305298233.87" />
	<link rel="stylesheet" type="text/css" href="assets/api.css?stamp=1305298233.87" />

    <script type="text/javascript" src="assets/api-js?stamp=1305298233.87"></script>
    <script type="text/javascript" src="assets/ac-js?stamp=1305298233.87"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">
	<div id="hd">
        <h1><a href="http://developer.yahoo.com/yui/" title="Yahoo! UI Library">Yahoo! UI Library</a></h1>
        <h3>CWN2&nbsp; <span class="subtitle">1.0.0</span></h3>
        <a href="./index.html" title="Yahoo! UI Library">Yahoo! UI Library</a> 
            &gt; <a href="./module_cwn2.html" title="CWN2">CWN2</a>
                
                 &gt; _event.js (source view) 
        <form onsubmit="return false">
            <div id="propertysearch">
                Search: <input autocomplete="off" id="searchinput" />
                <div id="searchresults">
                    &nbsp;
                </div>
            </div>
        </form>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form action="#" name="yui-classopts-form" method="get" id="yui-classopts-form">
                <fieldset>
                    <legend>Filters</legend>
                <span class="classopts"><input type="checkbox" name="show_private" id="show_private" /> <label for="show_private">Show Private</label></span>
                <span class="classopts"><input type="checkbox" name="show_protected" id="show_protected" /> <label for="show_protected">Show Protected</label></span>
                <span class="classopts"><input type="checkbox" name="show_deprecated" id="show_deprecated" /> <label for="show_deprecated">Show Deprecated</label></span>
                </fieldset>
            </form>

                    <div id="srcout">
                        <style>
                            #doc3 .classopts { display:none; }
                        </style>
<div class="highlight"><pre><span class="c1">//#include &lt;_base.js&gt;</span>

<span class="c1">// Funzioni di callback</span>

<span class="cm">/**</span>
<span class="cm">* CWN2</span>
<span class="cm">*</span>
<span class="cm">* @module CWN2</span>
<span class="cm">*/</span>

<span class="c1">//Namespace</span>
<span class="nx">CWN2</span><span class="p">.</span><span class="nx">event</span> <span class="o">=</span> <span class="nx">CWN2</span><span class="p">.</span><span class="nx">event</span> <span class="o">||</span> <span class="p">{};</span>

<span class="cm">/**</span>
<span class="cm">* </span>
<span class="cm">* Funzione di callback che viene chiamata in seguito ad un evento di select</span>
<span class="cm">* su una feature vettoriale</span>
<span class="cm">* </span>
<span class="cm">* @namespace CWN2.event</span>
<span class="cm">* @class onFeatureSelect</span>
<span class="cm">* </span>
<span class="cm">* @param {obj} evt Oggetto evento</span>
<span class="cm">* </span>
<span class="cm">*/</span>

<span class="nx">CWN2</span><span class="p">.</span><span class="nx">event</span><span class="p">.</span><span class="nx">onFeatureSelect</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">evt</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">feature</span> <span class="o">=</span> <span class="nx">evt</span><span class="p">.</span><span class="nx">feature</span><span class="p">;</span>

    <span class="c1">// se impostato attributo infoUrl sul GeoJSON con i dati uso quello</span>
    <span class="c1">// altrimenti uso la infoUrl definita sulla configurazione del layer</span>
    <span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="nx">feature</span><span class="p">.</span><span class="nx">attributes</span><span class="p">.</span><span class="nx">infoUrl</span><span class="p">;</span>
    <span class="kd">var</span> <span class="nx">target</span> <span class="o">=</span> <span class="nx">feature</span><span class="p">.</span><span class="nx">attributes</span><span class="p">.</span><span class="nx">infoTarget</span><span class="p">;</span>
	<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">url</span><span class="p">)</span> <span class="p">{</span>
		<span class="kd">var</span> <span class="nx">layerName</span> <span class="o">=</span> <span class="nx">evt</span><span class="p">.</span><span class="nx">object</span><span class="p">.</span><span class="nx">name</span><span class="p">;</span>
		<span class="kd">var</span> <span class="nx">layerConfig</span> <span class="o">=</span> <span class="nx">CWN2</span><span class="p">.</span><span class="nx">configuration</span><span class="p">.</span><span class="nx">getLayerConfigByName</span><span class="p">(</span><span class="nx">layerName</span><span class="p">);</span>
		<span class="nx">url</span> <span class="o">=</span> <span class="nx">layerConfig</span><span class="p">.</span><span class="nx">infoUrl</span><span class="p">;</span>
		<span class="nx">target</span> <span class="o">=</span> <span class="nx">layerConfig</span><span class="p">.</span><span class="nx">infoTarget</span><span class="p">;</span>
		<span class="c1">// attribute replacement {$attribute_name} - utilizzo la funzione OpenLayers.Style.createLiteral</span>
		<span class="nx">url</span> <span class="o">=</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Style</span><span class="p">.</span><span class="nx">createLiteral</span><span class="p">(</span><span class="nx">url</span><span class="p">,</span><span class="nx">feature</span><span class="p">.</span><span class="nx">attributes</span><span class="p">,</span><span class="nx">feature</span><span class="p">);</span>
	<span class="p">}</span>
	
	<span class="k">if</span> <span class="p">(</span><span class="nx">url</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="nx">target</span><span class="p">)</span> <span class="p">{</span>
			<span class="nb">window</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="nx">url</span><span class="p">,</span><span class="nx">target</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">);</span>
		<span class="p">}</span>
		<span class="k">else</span> <span class="p">{</span>
			<span class="nb">window</span><span class="p">.</span><span class="nb">document</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">href</span><span class="o">=</span><span class="nx">url</span><span class="p">;</span>
		<span class="p">}</span>
	<span class="p">}</span>
<span class="p">};</span>


<span class="nx">CWN2</span><span class="p">.</span><span class="nx">event</span><span class="p">.</span><span class="nx">onFeatureUnselect</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">evt</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">feature</span> <span class="o">=</span> <span class="nx">evt</span><span class="p">.</span><span class="nx">feature</span><span class="p">;</span>
<span class="p">};</span>



<span class="cm">/* funzioni per gestione popup</span>
<span class="cm">CWN2.event.onPopupClose = function(evt) {</span>
<span class="cm">    // &#39;this&#39; is the popup.</span>
<span class="cm">    selectControl.unselect(this.feature);</span>
<span class="cm">}</span>

<span class="cm">CWN2.event.onFeatureSelect = function(evt) {</span>
<span class="cm">    feature = evt.feature;</span>
<span class="cm">    popup = new OpenLayers.Popup.FramedCloud(&quot;featurePopup&quot;,</span>
<span class="cm">                             feature.geometry.getBounds().getCenterLonLat(),</span>
<span class="cm">                             new OpenLayers.Size(100,100),</span>
<span class="cm">                             &quot;&lt;h2&gt;&quot;+feature.attributes.title + &quot;&lt;/h2&gt;&quot; +</span>
<span class="cm">                             feature.attributes.description,</span>
<span class="cm">                             null, true, onPopupClose);</span>
<span class="cm">    feature.popup = popup;</span>
<span class="cm">    popup.feature = feature;</span>
<span class="cm">    this.addPopup(popup);</span>
<span class="cm">}</span>

<span class="cm">CWN2.event.onFeatureUnselect = function(evt) {</span>
<span class="cm">    feature = evt.feature;</span>
<span class="cm">    if (feature.popup) {</span>
<span class="cm">        popup.feature = null;</span>
<span class="cm">        this.removePopup(feature.popup);</span>
<span class="cm">        feature.popup.destroy();</span>
<span class="cm">        feature.popup = null;</span>
<span class="cm">    }</span>
<span class="cm">}</span>
<span class="cm">*/</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div id="moduleList" class="module">
                        <h4>Modules</h4>
                        <ul class="content">
                                <li class="selected"><a href="module_CWN2.html" title="CWN2">CWN2</a></li>
                        </ul>
                    </div>

                    <div id="classList" class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="CWN2.base.loadJSON.html" title="CWN2.base.loadJSON">CWN2.base.loadJSON</a></li>
                                <li class=""><a href="CWN2.base.loadJSONasync.html" title="CWN2.base.loadJSONasync">CWN2.base.loadJSONasync</a></li>
                                <li class=""><a href="CWN2.configuration.html" title="CWN2.configuration">CWN2.configuration</a></li>
                                <li class=""><a href="CWN2.event.onFeatureSelect.html" title="CWN2.event.onFeatureSelect">CWN2.event.onFeatureSelect</a></li>
                        </ul>
                    </div>

                    <div id="fileList" class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class=""><a href="_base.js.html" title="_base.js">_base.js</a></li>
                                <li class="selected"><a href="_event.js.html" title="_event.js">_event.js</a></li>
                                <li class=""><a href="configuration.js.html" title="configuration.js">configuration.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2011 Yahoo! Inc. All rights reserved.
	</div>
</div>
<script type="text/javascript">
    ALL_YUI_PROPS = [{"url": "CWN2.configuration.html#property_controls", "access": "", "host": "CWN2.configuration", "type": "property", "name": "controls"}, {"url": "CWN2.configuration.html#method_getLayerConfigByName", "access": "", "host": "CWN2.configuration", "type": "method", "name": "getLayerConfigByName"}, {"url": "CWN2.configuration.html#property_layers", "access": "", "host": "CWN2.configuration", "type": "property", "name": "layers"}, {"url": "CWN2.configuration.html#property_layout", "access": "", "host": "CWN2.configuration", "type": "property", "name": "layout"}, {"url": "CWN2.configuration.html#method_load", "access": "", "host": "CWN2.configuration", "type": "method", "name": "load"}, {"url": "CWN2.configuration.html#property_mapOptions", "access": "", "host": "CWN2.configuration", "type": "property", "name": "mapOptions"}];
</script>
</body>
</html>
